#include <stdio.h>
#include <stdlib.h>

int main (int argc, char const* argv[])
{
    int m, n, count[10001], i, t, first, second;

    while (EOF != scanf("%d %d", &n, &m)) {
        if (n == 0 && m == 0) break;

        for (i = 0; i < 10001; i++) {
            count[i] = 0;
        }

        for (i = 0; i < n * m; i++) {
            scanf("%d", &t);
            count[t]++;
        }

        first = second = count[0];
        for (i = 1; i < 10001; i++) {
            if (count[i] > first) {
                second = first;
                first = count[i];
            } else if (count[i] < first && count[i] > second) {
                second = count[i];
            }
        }

        for (i = 0; i < 10001; i++) {
            if (count[i] == second) {
                printf("%d ", i);
            }
        }
        printf("\n");
    }

    return 0;
}
